﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SLAdmin.UserControls;
using Common.Admin;
using Common;
using Common.Controls;

namespace SLAdmin
{
    public partial class SplitScreen : UserControl
    {
        StudyList _studyList;
        public SplitScreen()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            _studyList = new StudyList();
            ccNav.Content = _studyList;            
            _studyList.SurveyPageSelected += new StudyList.SurveyPageSelectedDelegate(l_SurveyPageSelected);
            _studyList.SurveySelected += new StudyList.SurveySelectedDelegate(l_SurveySelected);
            _studyList.StudySelected += new StudyList.StudySelectedDelegate(l_StudySelected);
            _studyList.StudyWaveSelected += new StudyList.StudyWaveSelectedDelegate(l_StudyWaveSelected);
            _studyList.ConditionSelected += new StudyList.ConditionSelectedDelegate(l_ConditionSelected);
            _studyList.StudiesSelected += new StudyList.StudiesSelectedDelegate(_studyList_StudiesSelected);
        }

        void _studyList_StudiesSelected(List<Study> Studies)
        {
            EditStudies es = new EditStudies(Studies);
            es.StudiesUpdated += new EditStudies.StudiesUpdatedDelegate(delegate()
            {
                _studyList.PopulateTreeView();
            });
            ccMain.Content = es;
        }
        void l_ConditionSelected(Condition Condition, Study Study)
        {
            EditCondition ec = new EditCondition(Condition,Study);
            ec.ConditionUpdated += new EditCondition.ConditionUpdatedDelegate(delegate()
            {
                _studyList.PopulateTreeView();
            });
            ccMain.Content = ec;
        }

        void l_StudyWaveSelected(StudyWave StudyWave,Condition myCondition)
        {            
            EditStudyWave ese = new EditStudyWave(StudyWave, myCondition);
            ese.StudyWaveUpdated += new EditStudyWave.StudyWaveUpdatedDelegate(delegate()
            {
                _studyList.PopulateTreeView();
            });
            ccMain.Content = ese;
        }

        void l_StudySelected(Study Study)
        {
            EditStudy es = new EditStudy(Study);
            es.StudyUpdated += new EditStudy.StudyUpdatedDelegate(delegate()
            {
                _studyList.PopulateTreeView();
            });
            ccMain.Content = es;
        }

        void l_SurveySelected(Survey Survey)
        {
            EditSurvey es = new EditSurvey(Survey);
            es.SurveyUpdated += new EditSurvey.SurveyUpdatedDelegate(delegate()
            {
                _studyList.PopulateTreeView();
            });
            ccMain.Content = es;         
            
        }

        void l_SurveyPageSelected(SurveyPage SurveyPage)
        {
            EditSurveyPage esp = new EditSurveyPage(SurveyPage);            
            esp.SurveyPageUpdated += new EditSurveyPage.SurveyPageUpdatedDelegate(delegate()
            {
                _studyList.PopulateTreeView();
            });
            ccMain.Content = esp;
        }

        private void UserControl_LayoutUpdated(object sender, EventArgs e)
        {
            StudyList sl = ccNav.Content as StudyList;
            if (sl != null)
            {
                sl.Width = ccNav.ActualWidth;
                sl.Height = ccNav.ActualHeight;
            }            
            UserControl ccMainContent = ccMain.Content as UserControl;
            if (ccMainContent != null)
            {
                ccMainContent.Width = ccMain.ActualWidth;
                ccMainContent.Height = ccMain.ActualHeight;
            }
        }
    }
}
